package middlewarex

import (
	"github.com/gin-gonic/gin"
	"zhonghui/console/service"
	"zhonghui/console/warehouse/respx"
)

func NeedAuth() gin.HandlerFunc {
	return func(c *gin.Context) {
		user := service.GetUserFromToken(c.GetHeader("Authorization"))
		if user == nil {
			respx.UnAuth(c)
			return
		}

		c.Next()
	}
}
